package main;

import java.util.ArrayList;

import BUS.SearchEngine;
import DTO.ChiTietDichVuDTO;
import Nhom7.mainPackage.main.R;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

public class ViewMenu extends Activity {

	// private final int maxMenuItems = 10;
	private SearchEngine searchEngine;
	private Bundle extras;
	private String name;
	private Double latiTude;
	private Double longiTude;
	private int maDuLieu;
	private ImageButton viewMapBtn;
	private ImageButton viewMain;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.view_menu);
		extras = getIntent().getExtras();
		name = extras.getString("Ten");
		maDuLieu = extras.getInt("DuLieu");
		latiTude = extras.getDouble("Vi_Do");
		longiTude = extras.getDouble("Kinh_Do");
		viewMapBtn = (ImageButton) this.findViewById(R.id.buttonViewMap);
		viewMapBtn.setImageResource(R.drawable.maps);
		viewMapBtn.setOnClickListener(new viewMapBtnClick());
		viewMain = (ImageButton) this.findViewById(R.id.toMainFromMenu);
		viewMain.setImageResource(R.drawable.go_previous_blue);
		viewMain.setOnClickListener(new viewMainBtnClick());

		try {
			Context contex = this;
			searchEngine = new SearchEngine(contex);
		} catch (Exception e) {
			// TODO: handle exception
		}
		TextView tv1 = (TextView) this.findViewById(R.id.tv1);
		tv1.setText("");

		tv1.setText("Menu của " + name + " gồm: ");

		ListView lv1 = (ListView) this.findViewById(R.id.listViewMenu);

		ArrayList<ChiTietDichVuDTO> listChiTietDV = searchEngine
				.SearchChiTietDV(maDuLieu);

		String menu[] = new String[listChiTietDV.size()];
		for (int i = 0; i < listChiTietDV.size(); i++) {
			menu[i] = listChiTietDV.get(i).Ten() + "\t"
					+ listChiTietDV.get(i).GiaTien() + "\n"
					+ listChiTietDV.get(i).ChuThich();
		}

		lv1.setAdapter(new android.widget.ArrayAdapter<String>(this,
				android.R.layout.simple_list_item_1, menu));

	}

	class viewMapBtnClick implements OnClickListener {
		public void onClick(View v) {
			loadMapScr();
		}
	}

	void loadMapScr() {
		Intent i = new Intent(this, ViewMap.class);
		i.putExtra("Ten", name);
		i.putExtra("DuLieu", maDuLieu);
		i.putExtra("Vi_Do", latiTude);
		i.putExtra("Kinh_Do", longiTude);
		startActivityForResult(i, 1);

	}

	class viewMainBtnClick implements OnClickListener {
		public void onClick(View v) {
			viewMain();
		}
	}

	void viewMain() {
		Intent i = new Intent(this, main.class);
		startActivityForResult(i, 1);
	}
}
